package com.jsnkj.basic.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.jsnkj.basic.R
import com.jsnkj.basic.bean.WithdrawalsEntity


class WithDrawMoneyAdapter(
    val context: Context,
    private val itemBeans: List<WithdrawalsEntity>,
    val itemClick: onItemClickListener
) :
    RecyclerView.Adapter<WithDrawMoneyAdapter.HomeViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeViewHolder {
        val view: View =
            LayoutInflater.from(parent.context)
                .inflate(R.layout.rv_item_with_draw_money, parent, false)
        return HomeViewHolder(view)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: HomeViewHolder, position: Int) {

        var bean = itemBeans[position]
        holder.tvTitle.setText("${bean.value}元")

        if (bean.label.isNullOrEmpty()) {
            holder.tvLogo.visibility = View.GONE
            holder.tvLogo.text = ""
        } else {
            holder.tvLogo.visibility = View.VISIBLE
            holder.tvLogo.text = bean.label
        }

        if (bean.isSelect) {
            holder.conLayoutItem.setBackgroundResource(R.drawable.bg_item_with_draw_true)
            holder.tv1.setTextColor(holder.tv1.context.getColor(R.color.white))
            holder.tvTitle.setTextColor(holder.tvTitle.context.getColor(R.color.white))

        } else {
            holder.conLayoutItem.setBackgroundResource(R.drawable.bg_item_with_draw_false)
            holder.tv1.setTextColor(holder.tv1.context.getColor(R.color.color9F602A))
            holder.tvTitle.setTextColor(holder.tvTitle.context.getColor(R.color.color9F602A))

        }

        holder.conLayoutItem.setOnClickListener {
            if (null != itemClick) {
                itemClick.onItemCallBack(position)
            }
        }
    }

    override fun getItemCount(): Int {
        return itemBeans.size
    }

    class HomeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var conLayoutItem: ConstraintLayout
        var tvTitle: TextView
        var tv1: TextView
        var tvLogo: TextView

        init {
            conLayoutItem = itemView.findViewById<ConstraintLayout>(R.id.con_layout_item)
            tvTitle = itemView.findViewById<TextView>(R.id.tv_money_title)
            tv1 = itemView.findViewById<TextView>(R.id.tv_1)
            tvLogo = itemView.findViewById<TextView>(R.id.tv_logo)
        }
    }


    interface onItemClickListener {
        fun onItemCallBack(position: Int)
    }
}